package cn.elves.model.auth.controller;

import cn.elves.model.auth.entity.dto.InterFaceDTO;
import cn.elves.model.auth.entity.po.Interface;
import cn.elves.model.auth.service.InterfaceService;
import cn.elves.model.entity.dto.response.ResponseDTO;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
public class InterFaceController {

    @Resource
    private InterfaceService interfaceService;

    @GetMapping("interface/page/{pageNum}/{pageSize}")
    public ResponseDTO<Page<Interface>> getInterfacePage(@PathVariable("pageNum") Integer pageNum, @PathVariable("pageSize") Integer pageSize) {

        return ResponseDTO.success(interfaceService.page(new Page<>(pageNum,pageSize)));
    }

    @GetMapping("interface/{id}")
    public ResponseDTO<Interface> getInterfaceDetail(@PathVariable("id") Long id) {
        return ResponseDTO.success(interfaceService.getById(id));
    }

    @PostMapping("interface")
    public ResponseDTO<Interface> saveInterface(@RequestBody InterFaceDTO interFaceDTO) {
        interfaceService.save(interFaceDTO.toInterface());
        return ResponseDTO.success();
    }

    @PutMapping("interface")
    public ResponseDTO<Interface> updateInterface(@RequestBody InterFaceDTO interFaceDTO) {
        interfaceService.updateById(interFaceDTO.toInterface());
        return ResponseDTO.success();
    }

    @DeleteMapping("interface/{id}")
    public ResponseDTO<Interface> deleteInterFaceById(@PathVariable("id") Long id) {
        interfaceService.removeById(id);
        return ResponseDTO.success();
    }

}
